﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Data.Api.Repositories;

namespace Data.Repositories
{
    public class CategoriesRepository : Repository<Entity.Categories.Category, Data.ModelDatabase.Category>, ICategoriesRepository
    {

        public CategoriesRepository(Db.IDbShopConcreteContext context, Mappers.IMapper<Entity.Categories.Category, Data.ModelDatabase.Category> mapper) : base(context, context.Categories, mapper)
        { }

        public override void Update(Entity.Categories.Category entity)
        {
            Data.ModelDatabase.Category category = dbSet.Find(entity.Id);
            category.Description = entity.Description;
            category.Name = entity.Name;

            context.Context.Entry(category).State = System.Data.EntityState.Modified;
        }

        public override void Insert(Entity.Categories.Category entity)
        {
            Data.ModelDatabase.Category category = new ModelDatabase.Category() { Description = entity.Description, Name = entity.Name };
            category.Products = new List<Data.ModelDatabase.Product>();

            context.Categories.Add(category);
        }
    }
}
